package org.webcamp.settings.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.webcamp.settings.services.SettingsService;

@Controller
public class SettingsController {

	private SettingsService settingsService;
	
	public void setSettingsService(SettingsService settingsService) {
		this.settingsService = settingsService;
	}

	@RequestMapping("settings")
	public ModelAndView admin() {
		return new ModelAndView("settings", "settings", settingsService.loadSettings());
	}
	
	@RequestMapping("apply_settings")
	public ModelAndView setSetting(
			@RequestParam("name") String name,
			@RequestParam("value") String value) {
		settingsService.setSettings(name, value);
		return new ModelAndView("settings", "settings", settingsService.loadSettings());
	}
}
